package com.ax.base.drugproducer.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ax.base.drugproducer.domain.BaseProducer;

@Mapper
public interface BaseProducerMapper {
    int deleteByPrimaryKey(Long producerId);

    int insert(BaseProducer record);

    @Insert("insert into base_producer (Producer_ID, Producer_Name, First_Letter," +
    	     "Legal_Person_Name, Legal_Person_ID, Credit_Code, Reg_Date, Reg_Capital, Area_Code," +
    	     "Area_Name, Address, Phone, Account, BANK, Introduction," +
    	     "Remarks, create_date, update_date," +
    	     "Flag)" +
    	     "values (#{producerId}, #{producerName}, #{firstLetter},"+ 
    	     "#{legalPersonName}, #{legalPersonId}, #{creditCode},"+
    	     "#{regDate}, #{regCapital}, #{areaCode},"+ 
    	     "#{areaName}, #{address}, #{phone},"+ 
    	     "#{account}, #{bank}, #{introduction},"+ 
    	     "#{remarks}, NOW(), #{updateDate},"+ 
    	     "#{flag})")
    int insertSelective(BaseProducer baseProducer);

    BaseProducer selectByPrimaryKey(Long producerId);

    int updateByPrimaryKeySelective(BaseProducer record);

    int updateByPrimaryKey(BaseProducer record);
   
    /**
	 * 药品厂家
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return List<BaseProducer>
	 */
    @Select("<script>"+
    		"select "+
    		"Producer_ID, Producer_Name, First_Letter, Legal_Person_Name, Legal_Person_ID, Credit_Code,"+ 
    	    "Reg_Date, Reg_Capital, Area_Code, Area_Name, Address, Phone, Account, BANK, Introduction, "+
    	    "Remarks, create_date, update_date, Flag "+
	        "from base_producer where Producer_ID != #{producerId} and Credit_Code = #{creditCode}"+
            "</script>")
	List<BaseProducer> validateMapper(Map<String, Object> params);
    
    /**
	 * 药品厂家(修改代码验证)
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return List<BaseProducer>
	 */
    @Select("<script>"+
    		"select "+
    		"Producer_ID, Producer_Name, First_Letter, Legal_Person_Name, Legal_Person_ID, Credit_Code,"+ 
    	    "Reg_Date, Reg_Capital, Area_Code, Area_Name, Address, Phone, Account, BANK, Introduction, "+
    	    "Remarks, create_date, update_date, Flag "+
	        "from base_producer"+
	        "<where>" + 
	        "<if test=\"producerId != null\">"+ "and Producer_ID = #{producerId} " + "</if>" + 
	        "<if test=\"creditCode != null and creditCode != ''\">"+ "and Credit_Code = #{creditCode} " + "</if>" + 
    	  	"</where>"+
    	  /*"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+*/
            "</script>")
	List<BaseProducer> queryDrugproducerMapper(Map<String, Object> params);
    
    /**
	 * 药品厂家(分页总计)
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return Integer
	 */
    @Select("<script>"+
    		"select "+
    		"count(0) "+
	        "from base_producer"+
	        "<where>" + 
	        "<if test=\"producerId != null\">"+ "and Producer_ID = #{producerId} " + "</if>" + 
    	  	"</where>"+
            "</script>")
    Integer count(Map<String, Object> params);
    
    /**
	 * 药品厂家修改(模块:药品厂家)*跳转修改页面
	 * 
	 * @param Long id
	 *           
	 * @return HTML
	 */
    @Select("<script>"+
    		"select "+
    		"Producer_ID, Producer_Name, First_Letter, Legal_Person_Name, Legal_Person_ID, Credit_Code,"+ 
    	    "Reg_Date, Reg_Capital, Area_Code, Area_Name, Address, Phone, Account, BANK, Introduction, "+
    	    "Remarks, create_date, update_date, Flag "+
	        "from base_producer"+
	        "<where>" + 
	        "<if test=\"producerId != null\">"+ "and Producer_ID = #{producerId} " + "</if>" + 
    	  	"</where>"+
            "</script>")
    BaseProducer getProducerMapper(@Param("producerId") Long producerId);
    
    @Update("<script>"+
            "update base_producer "+
            "<set >"+
            "<if test=\"producerName != null and producerName != ''\">"+ "Producer_Name = #{producerName}, " + "</if>" +
            "<if test=\"firstLetter != null and firstLetter != ''\">"+ "First_Letter = #{firstLetter}, " + "</if>" +
            "<if test=\"legalPersonName != null and legalPersonName != ''\">"+ "Legal_Person_Name = #{legalPersonName}, " + "</if>" +
            "<if test=\"legalPersonId != null\">"+ "Legal_Person_ID = #{legalPersonId}, " + "</if>" +
            "<if test=\"creditCode != null and creditCode != ''\">"+ "Credit_Code = #{creditCode}, " + "</if>" +
            "<if test=\"regDate != null\">"+ "Reg_Date = #{regDate}, " + "</if>" +
            "<if test=\"regCapital != null\">"+ "Reg_Capital = #{regCapital}, " + "</if>" +
            "<if test=\"areaCode != null and areaCode != ''\">"+ "Area_Code = #{areaCode}, " + "</if>" +
            "<if test=\"areaName != null and areaName != ''\">"+ "Area_Name = #{areaName}, " + "</if>" +
            "<if test=\"address != null and address != ''\">"+ "Address = #{address}, " + "</if>" +
            "<if test=\"phone != null and phone != ''\">"+ "Phone = #{phone}, " + "</if>" +
            "<if test=\"account != null and account != ''\">"+ "Account = #{account}, " + "</if>" +
            "<if test=\"bank != null and bank != ''\">"+ "BANK = #{bank}, " + "</if>" +
            "<if test=\"introduction != null and introduction != ''\">"+ "Introduction = #{introduction}, " + "</if>" +
            "<if test=\"remarks != null and remarks != ''\">"+ "Remarks = #{remarks}, " + "</if>" +
            "<if test=\"createDate != null and createDate != ''\">"+ "create_date = #{createDate}, " + "</if>" +
            "<if test=\"updateDate != null and updateDate != ''\">"+ "update_date = #{updateDate}, " + "</if>" +
            "<if test=\"flag != null\">"+ "Flag = #{flag}, " + "</if>" +
            "</set>"+
            "where Producer_ID = #{producerId,jdbcType=BIGINT}"+
            "</script>"
    		)
    void updateBaseDrugMapper(BaseProducer baseProducer);
}